package org.geektimes.projects.user.logging;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

/**
 * @Author: jipeng
 * @Description:
 * @Date: Created in 2021/3/15 7:21
 */
public class UserWebLoggingConfiguration {

    public UserWebLoggingConfiguration() throws Exception {
        System.out.println("UserWebLoggingConfiguration");

        //TODO 动态调整Logger 信息
        Logger logger = Logger.getLogger("org.geektimes");
        ConsoleHandler consoleHandler = new ConsoleHandler();
        consoleHandler.setEncoding("UTF-8");
        consoleHandler.setLevel(Level.WARNING);

        logger.addHandler(consoleHandler);
    }


    public static void main(String[] args) throws IOException {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Logger logger = Logger.getLogger("org.geektimes");

        try(InputStream stream = classLoader.getResourceAsStream("META-INF/logging.properties")){
            LogManager logManager = LogManager.getLogManager();

            logManager.readConfiguration(stream);
        }

        logger.info("Hello,word");
        logger.warning("2021-03-15");
    }


}
